<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue Test</title>
    <style>
        .fade-enter-active, .fade-leave-active {
            transition: opacity 3s;
        }
        .fade-enter, .fade-leave-to {
            opacity: 0;
        }
    </style>
</head>
<body>
    <div id="app">
        {{ message }}
    </div>
    <div id="app-2">
        <span v-bind:title="message">
            鼠标悬停几秒查看此处动态绑定提示信息！
        </span>
    </div>
    <div id="app-3">
        <p v-if="seen">现在你看到我了</p>
    </div>
    <div id="demo">
        <button v-on:click="show = !show">
            Toggle
        </button>
        <transition name="fade">
            <p v-if="show">Hello</p>
        </transition>
    </div>
    <div id="app-4">
        <ol>
            <li v-for="todo in todos">
                {{ todo.text }}
            </li>
        </ol>
    </div>
    <div id="app-5">
        <p>{{ message }}</p>
        <button v-on:click="reverseMessage">反转消息</button>
    </div>
    <div id="app-6">
        <p>{{ message }}</p>
        <a v-bind:[attribute]=url>百度</a>
        <p v-once>这个将不会改变: {{ message }}</p>
        <input v-model="message">
        <p>Using mustaches: {{ rawHtml }}</p>
        <p>Using v-html directive: 
            <span v-html="rawHtml"></span>
        </p>
        <p>Original message: "{{ message }}"</p>
        <p>Computed reversed message: "{{ reversedMessage }}"</p>
        <p>Using function to reverse it: "{{ reverseMessage() }}"</p>
        <p>{{ fullName }}</p>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <script>
        var app = new Vue({
            el:"#app",
            data: {
                message: "Hello Vue!"
            }
        });
        var app2 = new Vue({
            el: "#app-2",
            data: {
                message: "页面加载于 " + new Date().toLocaleString()
            }
        });
        var app3 = new Vue({
            el: "#app-3",
            data: {
                seen: true
            }
        });
        new Vue({
            el: "#demo",
            data: {
                show: true
            }
        });
        var app4 = new Vue({
            el: "#app-4",
            data: {
                todos: [
                    { text: "学习javascript" },
                    { text: "学习Vue" },
                    { text: "整个牛项目" }
                ]
            }
        });
        var app5 = new Vue({
            el: "#app-5",
            data: {
                message: "Hello Vue.js!"
            },
            methods: {
                reverseMessage: function() {
                    this.message = this.message.split("").reverse().join("")
                }
            }
        });
        var app6 = new Vue({
            el: "#app-6",
            data: {
                attribute: 'href',
                url: 'www.baidu.com',
                message: "Hello Vue!",
                firstName: "Feng",
                lastName: "Bar",
                // fullName: "Foo Bar",
                rawHtml: '<span style="color: red">This should be red.</span>'
            },
            methods: {
                reverseMessage: function() {
                    return this.message.split('').reverse().join('');
                }
            },
            computed: {
                reversedMessage: function() {
                    return this.message.split('').reverse().join('');
                },
                fullName: function() {
                    return this.firstName + " " + this.lastName
                }
            },
            // watch :{
            //     firstName: function(val) {
            //         this.fullName = val + " " + this.lastName
            //     },
            //     lastName: function(val) {
            //         this.fullName = this.firstName + " " + val
            //     }
            // }
        })
    </script>
</body>
</html>